package C;

import java.util.*;
import java.util.stream.Collectors;

public class C16 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nums = new String[5];
        String[] hua = new String[5];
        for (int i=0;i<5;i++) {
            nums[i] = sc.next();
            hua[i] = sc.next();
        }
        System.out.println(getResult(nums,hua));
    }

    public static int getResult(String[] nums,String[] hua) {
        int a = isShun(nums,hua);
        int b = isTiao(nums);
        return a<b? a : b;
    }

    public static int isTiao(String[] nums) {
        HashMap<String,Integer> map = new HashMap<>();
        for (String num : nums) {
            map.put(num, map.getOrDefault(num,0)+1);
        }
        int mostNum = map.values().stream().max(Integer::compareTo).get();
        int mostHua = map.keySet().size();
        if (mostNum == 4 ) return 2;
        if (mostNum == 3 && mostHua == 2) return 3;
        if (mostNum == 3 && mostHua ==3) return 6;
        return 10;
    }

    public static int isShun(String[] nums,String[] hua) {
        int shun = 1,tong =0;
        int[] newNums = new int[5];
        for (int i=0;i<5;i++) {
            if (nums[i].equals("J")) {
                newNums[i] = 11;
            } else if(nums[i].equals("Q")) {
                newNums[i] = 12;
            } else if (nums[i].equals("K")) {
                newNums[i] = 13;
            } else if (nums[i].equals("A")) {
                newNums[i] = 14;
            } else {
                newNums[i] = Integer.parseInt(nums[i]);
            }
        }

        Arrays.sort(newNums);
        if(Arrays.stream(newNums)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining(""))
                .equals("234514")) {
            shun = 1;
        } else {
            for (int i = 0; i < 4; i++) {
                if ((newNums[i] + 1) != (newNums[i + 1])) {
                    shun = 0;
                }
            }
        }
        if ( new HashSet<String>(Arrays.asList(hua)).size() == 1) {
            tong = 1;
        }

        if (Arrays.stream(hua).distinct().count() == 1) {
            tong = 1;
        }

        if (shun == 1 && tong == 1) return 1;
        if (tong == 1) return 4;
        if (shun == 1) return 5;

        return 10;
    }
}
